/*
 * This file is part of aion-lightning <aion-lightning.com>.
 *
 *  aion-lightning is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  aion-lightning is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with aion-lightning.  If not, see <http://www.gnu.org/licenses/>.
 */
package quest.talocs_hollow;

import com.aionemu.gameserver.dataholders.DataManager;
import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.network.aion.SystemMessageId;
import com.aionemu.gameserver.network.aion.serverpackets.SM_SYSTEM_MESSAGE;
import com.aionemu.gameserver.questEngine.handlers.QuestHandler;
import com.aionemu.gameserver.model.DialogAction;
import com.aionemu.gameserver.questEngine.model.QuestEnv;
import com.aionemu.gameserver.questEngine.model.QuestState;
import com.aionemu.gameserver.questEngine.model.QuestStatus;
import com.aionemu.gameserver.services.QuestService;
import com.aionemu.gameserver.utils.PacketSendUtility;


/**
 * @author Cheatkiller
 *
 */
public class _11467DeathToTheQueen extends QuestHandler {
	
	private final static int questId = 11467;
	
	public _11467DeathToTheQueen(){
		super(questId);
	}
		@Override
		public void register() {
			qe.registerOnDie(questId);
			qe.registerOnLogOut(questId);
			qe.registerOnQuestTimerEnd(questId);
			qe.registerQuestNpc(799527).addOnQuestStart(questId);
			qe.registerQuestNpc(799503).addOnTalkEvent(questId);
			qe.registerQuestNpc(215480).addOnKillEvent(questId);
		}
		
		@Override
		public boolean onDialogEvent(QuestEnv env) {
			Player player = env.getPlayer();
			QuestState qs = player.getQuestStateList().getQuestState(questId);
			DialogAction dialog = env.getDialog();
			int targetId = env.getTargetId();

			if (qs == null || qs.getStatus() == QuestStatus.NONE) {
				if (targetId == 799527) { 
					if (dialog == DialogAction.QUEST_SELECT) {
						return sendQuestDialog(env, 4762);
					}
					else if(dialog == DialogAction.QUEST_ACCEPT_1) {
						QuestService.questTimerStart(env, 480);
						return sendQuestStartDialog(env);
					}
					else {
						return sendQuestStartDialog(env);
					}
				}
			}
		  else if (qs.getStatus() == QuestStatus.REWARD) {
		  	int var = qs.getQuestVarById(0);
		  	int rewInd = 0;
		  	if(var == 1)
		  		rewInd = 1;
		  	else if(var == 2)
		  		rewInd = 2;
		  	else if(var == 3)
		  		rewInd = 3;
		  	if (targetId == 799503) {
					if (dialog == DialogAction.USE_OBJECT) {
						return sendQuestDialog(env, 10002);
					}
					else {
						return sendQuestEndDialog(env, rewInd);
					}
				}
			}
		return false;
	}
		
		@Override
		public boolean onKillEvent(QuestEnv env) {
			Player player = env.getPlayer();
			QuestState qs = player.getQuestStateList().getQuestState(questId);
			if (qs != null && qs.getStatus() == QuestStatus.START) {
				int targetId = env.getTargetId();
				int var = qs.getQuestVarById(0);
				if(targetId == 215480) {
					QuestService.questTimerEnd(env);
					changeQuestStep(env, var, var, true);
				  return true;
				}
			}
			return false;
		}
					
		@Override
		public boolean onQuestTimerEndEvent(QuestEnv env) {
			Player player = env.getPlayer();
			QuestState qs = player.getQuestStateList().getQuestState(questId);
			if (qs != null && qs.getStatus() == QuestStatus.START) {
				int var = qs.getQuestVarById(0);
				if(var == 0) {
					QuestService.questTimerStart(env, 240);
					changeQuestStep(env, 0, 1, false);
				}
				else if(var == 1) {
					QuestService.questTimerStart(env, 240);
					changeQuestStep(env, 1, 2, false);
				}
				else if(var == 3) {
					changeQuestStep(env, 2, 3, false);
				}
				return true;
			}
			return false;
		}
		
		@Override
		public boolean onDieEvent(QuestEnv env) {
			Player player = env.getPlayer();
			QuestState qs = player.getQuestStateList().getQuestState(questId);
			if (qs != null && qs.getStatus() == QuestStatus.START) {
				qs.setStatus(QuestStatus.NONE);
				qs.setQuestVar(0);
				updateQuestStatus(env);
				PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(SystemMessageId.QUEST_FAILED_$1,
					DataManager.QUEST_DATA.getQuestById(questId).getName()));
				return true;
			}
			return false;
		}
		
		@Override
		public boolean onLogOutEvent(QuestEnv env) {
			Player player = env.getPlayer();
			QuestState qs = player.getQuestStateList().getQuestState(questId);
			if (qs != null && qs.getStatus() == QuestStatus.START) {
				qs.setStatus(QuestStatus.NONE);
				qs.setQuestVar(0);
				updateQuestStatus(env);
			}
			return false;
		}
}
			

				
			

	
